package com.htht.smartschool.action.student;

import java.util.List;
import java.util.Map;

import com.htht.smartschool.action.baseaction.BaseAction;
import com.htht.smartschool.common.model.ParamData;
import com.htht.smartschool.common.servlet.DataContainer;
import com.htht.smartschool.model.exam.ExamResultAll;
import com.htht.smartschool.model.student.TStudent;
import com.htht.smartschool.service.student.StudentService;
import com.htht.smartschool.util.system.GsonUtils;
import com.htht.smartschool.util.system.ResultSetToExcel;

public class StudentAction extends BaseAction {
	
	@Override
	public boolean processData(DataContainer obj, ParamData pd) {
		StudentService studentService = new StudentService();
		boolean flag = false;
		TStudent tStudent = (TStudent) GsonUtils.getInstance().fromJson(pd.getData(), TStudent.class);
		if(pd.getCmd().equalsIgnoreCase("add")){
			TStudent student = studentService.add(tStudent);
			if(student != null){
				flag = true;
				obj.setData(student);
			}else{
				obj.setData("注册学生信息失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("update")){
			boolean student = studentService.updateInfo(tStudent);
			if(student){
				flag = true;
				obj.setData(student);
			}else{
				obj.setData("修改失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("delete")){
			boolean student = studentService.deleteInfo(tStudent.getStudentcode(), tStudent.getImei());
			if(student){
				flag = true;
				obj.setData(student);
			}else{
				obj.setData("删除失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("askForLeaveByStudentCode")){
			boolean result = studentService.askForLeaveByStudentCode(tStudent.getStudentcode());
			if(result){
				flag = true;
				obj.setData(result);
			}else{
				obj.setData("修改学生信息失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getAllStudentsByPage")){
			@SuppressWarnings("rawtypes")
			Map map = studentService.getAllStudentsByPage(tStudent);
			if(map != null){
				flag = true;
				obj.setData(map);
			}else{
				obj.setData("查询学生结果失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("bachDeleteStudents")){
			boolean result = studentService.bachDeleteStudents(tStudent);
			if(result){
				flag = true;
				obj.setData("删除成功");
			}else{
				obj.setData("删除学生结果失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("unLockStudent")){
			boolean result = studentService.unLockStudent(tStudent);
			if(result){
				flag = true;
				obj.setData("解锁成功");
			}else{
				obj.setData("解锁学生失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("addStudent")){
			TStudent student = studentService.addStudent(tStudent);
			if(student != null){
				flag = true;
				obj.setData(student);
			}else{
				obj.setData("注册学生信息失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("bindStudent")){
			TStudent student = studentService.bindStudent(tStudent);
			if(student != null){
				flag = true;
				obj.setData(student);
			}else{
				obj.setData("绑定学生信息失败！");
			}
		}
		return flag;
	}
}
